package com.demo.dao.impl;

import com.demo.dao.BookDao;
import com.demo.pojo.Book;
import com.demo.utils.ConnUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class BookDaoImpl implements BookDao {
    @Override
    public List<Book> queryBooks() throws SQLException {
        Connection conn = ConnUtil.getConn();
        String sql = "select * from lucene";
        QueryRunner qr = new QueryRunner();
        List<Book>  list = qr.query(conn, sql, new BeanListHandler<>(Book.class));
        conn.close();
        return list;
    }

    public static void main(String[] args) throws SQLException {
        BookDao bookDao = new BookDaoImpl();
        List<Book> list = bookDao.queryBooks();
        System.out.println(list.size());
    }
}
